home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / UPC12BS1.ZIP / LIB / HOSTRSET.C < prev    next >
C/C++ Source or Header  |  1993-05-02  |  6KB  |  143 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    h o s t r s e t . c                                             */
  3. /*                                                                    */
  4. /*    Clear host status information for UUPC/extended                 */
  5. /*                                                                    */
  6. /*    Copyright (c) 1992, Mitch Mitchell                              */
  7. /*--------------------------------------------------------------------*/
  8.  
  9. /*--------------------------------------------------------------------*/
  10. /*    Changes Copyright (c) 1990-1993 by Kendra Electronic            */
  11. /*    Wonderworks.                                                    */
  12. /*                                                                    */
  13. /*    All rights reserved except those explicitly granted by the      */
  14. /*    UUPC/extended license agreement.                                */
  15. /*--------------------------------------------------------------------*/
  16.  
  17. /*--------------------------------------------------------------------*/
  18. /*                          RCS Information                           */
  19. /*--------------------------------------------------------------------*/
  20.  
  21. /*
  22.  *    $Id: hostrset.c 1.3 1993/05/03 02:41:57 ahd Exp $
  23.  *
  24.  *    Revision history:
  25.  *    $Log: hostrset.c $
  26.  *     Revision 1.3  1993/05/03  02:41:57  ahd
  27.  *     Use correct directory for new status file
  28.  *
  29.  */
  30.  
  31. /*--------------------------------------------------------------------*/
  32. /*                        System include files                        */
  33. /*--------------------------------------------------------------------*/
  34.  
  35. #include <stdio.h>
  36. #include <string.h>
  37. #include <time.h>
  38.  
  39. /*--------------------------------------------------------------------*/
  40. /*                    UUPC/extended include files                     */
  41. /*--------------------------------------------------------------------*/
  42.  
  43. #include "lib.h"
  44. #include "hlib.h"
  45. #include "hostable.h"
  46. #include "hostatus.h"
  47. #include "hostrset.h"
  48. #include "security.h"
  49. #include "timestmp.h"
  50.  
  51. /*--------------------------------------------------------------------*/
  52. /*        Define current file name for panic() and printerr()         */
  53. /*--------------------------------------------------------------------*/
  54.  
  55. currentfile();
  56.  
  57. /*--------------------------------------------------------------------*/
  58. /*       H o s t R e s e t                                            */
  59. /*                                                                    */
  60. /*       Reset status information for one or more hosts               */
  61. /*--------------------------------------------------------------------*/
  62.  
  63. void HostReset( const char *name )
  64. {
  65.    boolean firsthost = TRUE;
  66.    struct HostTable *host;
  67.    char fname[FILENAME_MAX];
  68.    FILE *stream;
  69.    unsigned short len1 = strlen(compilep );
  70.    unsigned short len2 = strlen(compilev );
  71.  
  72. /*--------------------------------------------------------------------*/
  73. /*         Get the file name for the status file and open it          */
  74. /*--------------------------------------------------------------------*/
  75.  
  76.    mkfilename( fname, E_confdir, DCSTATUS );
  77.  
  78.    if ((stream  = FOPEN(fname , "w", BINARY_MODE)) == NULL)
  79.    {
  80.       printmsg(1,"HostReset: Unable to open host status file");
  81.       printerr( fname );
  82.       panic();                /* Critical error if unable to write   */
  83.       return;
  84.    } /* if */
  85.  
  86. /*--------------------------------------------------------------------*/
  87. /*                 Write header information for file                  */
  88. /*--------------------------------------------------------------------*/
  89.  
  90.    fwrite( &len1, sizeof len1, 1, stream );
  91.    fwrite( &len2, sizeof len2, 1, stream );
  92.    fwrite( compilep , 1, len1, stream);
  93.    fwrite( compilev , 1, len2, stream);
  94.    fwrite( &start_stats , sizeof start_stats , 1,  stream);
  95.  
  96. /*--------------------------------------------------------------------*/
  97. /*     Now spin through the hosts and write out their information     */
  98. /*--------------------------------------------------------------------*/
  99.  
  100.    while  ((host = nexthost( firsthost )) != BADHOST)
  101.    {
  102.       len1 = strlen( host->hostname );
  103.       len2 = sizeof *(host->hstats);
  104.  
  105.       firsthost = FALSE;
  106.  
  107.       fwrite( &len1, sizeof len1, 1, stream );
  108.       fwrite( &len2, sizeof len2, 1, stream );
  109.       fwrite( host->hostname , sizeof host->hostname[0], len1, stream);
  110.  
  111. /*--------------------------------------------------------------------*/
  112. /*                    Clear this host if requested                    */
  113. /*--------------------------------------------------------------------*/
  114.  
  115.       if ( (name == NULL) || equal(name,host->hostname) )
  116.       {
  117.           host->hstats->calls     = 0l;  /* Total number of calls to host       */
  118.           host->hstats->connect   = 0l;  /* Total length of connections to host */
  119.           host->hstats->fsent     = 0l;  /* Total files sent to this host       */
  120.           host->hstats->freceived = 0l;  /* Total files received from this host */
  121.           host->hstats->bsent     = 0l;  /* Total bytes sent to this host       */
  122.           host->hstats->breceived = 0l;  /* Total bytes received from this host */
  123.           host->hstats->errors    = 0l;  /* Total transmission errors noted     */
  124.           host->hstats->packets   = 0l;  /* Total packets exchanged             */
  125.       }
  126.  
  127.       host->hstats->save_hstatus = host->hstatus;
  128.       fwrite( host->hstats , len2, 1,  stream);
  129.    }
  130.  
  131. /*--------------------------------------------------------------------*/
  132. /*         Make we sure got end of file and not an I/O error          */
  133. /*--------------------------------------------------------------------*/
  134.  
  135.    if (ferror( stream ))
  136.    {
  137.       printerr( fname );
  138.       clearerr( stream );
  139.    }
  140.    fclose( stream );
  141.  
  142. } /* HostReset */
  143.